home *** CD-ROM | disk | FTP | other *** search
- Path: uunet!wyse!mips!apple!sun-barr!newstop!sun!sun.com!argv
- From: argv@sun.com
- Newsgroups: comp.sources.x
- Subject: v06i032: vine, Patch1
- Message-ID: <132964@sun.Eng.Sun.COM>
- Date: 15 Mar 90 07:44:17 GMT
- Sender: news@sun.Eng.Sun.COM
- Lines: 592
- Approved: argv@sun.com
-
- Submitted-by: argv@sun.com
- Posting-number: Volume 6, Issue 32
- Archive-name: vine/patch1
- Patch-To: vine: Volume 6, Issue 25
-
- The following patch to vine fixes the problem
- with forking. so, some of the more interesting
- parameters now workd:
- vine -C -c
- vince -CfDc
- Due to a bug with xnews, you're going to have a problem
- allocating colors correctly. It's been reported already.
-
- *** Imakefile.orig Sat Mar 10 12:41:04 1990
- --- Imakefile Wed Mar 14 11:19:36 1990
- ***************
- *** 2,8 ****
- #include BandAidCompiler
- #endif
-
- ! DEFINES -DX11
- INCLUDES = -I$(TOP) -I$(TOP)/X11
- SYS_LIBRARIES = -lm
- LOCAL_LIBRARIES = $(XLIB)
- --- 2,8 ----
- #include BandAidCompiler
- #endif
-
- ! DEFINES = -DX11
- INCLUDES = -I$(TOP) -I$(TOP)/X11
- SYS_LIBRARIES = -lm
- LOCAL_LIBRARIES = $(XLIB)
- *** version.h.orig Wed Mar 14 23:02:20 1990
- --- version.h Wed Mar 14 23:02:33 1990
- ***************
- *** 1,2 ****
- ! #define PATCHLEVEL 0
- ! #define PATCHDATE 3/9/90
- --- 1,2 ----
- ! #define PATCHLEVEL 1
- ! #define PATCHDATE 3/14/90
- *** vine.c.orig Fri Mar 9 18:44:25 1990
- --- vine.c Wed Mar 14 22:23:11 1990
- ***************
- *** 5,10 ****
- --- 5,13 ----
- *
- * compile: cc -O -s vine.c -lsunwindow -lpixrect -lm -o vine
- *
- + * Updating to work on X11 March 1990.
- + * compile: cc -O -s vine.c -DX11 -lX11 -lm -o vine
- + *
- * The way vines works is a "stem" grows and leaves grow from that stem.
- * The stem and the leaf are arrays of "points" (struct pr_pos). You can
- * add your own images (like flowers or something) with the -S and -L
- ***************
- *** 49,55 ****
- "-R N: have N different leaf rotations (max 360)",
- #ifdef X11
- "-d display: use display:server[.screen]",
- - "-F: allow forking; off by default because X server gets confused",
- #else /* X11 */
- "-d device: use alternate frame buffer; default is /dev/fb",
- "-w: vines grow around each window on the screen (not icons; no color)",
- --- 52,57 ----
- ***************
- *** 73,85 ****
- #include <X11/Xatom.h>
- #include <X11/Xlib.h>
- #include <X11/Xutil.h>
- ! struct pr_pos {
- ! short x, y;
- ! };
- struct rect {
- int r_left, r_top, r_width, r_height;
- };
- #else /* X11 */
- #include <suntool/tool_hs.h>
- #include <pixrect/pixrect_hs.h>
- #include <suntool/wmgr.h>
- --- 75,86 ----
- #include <X11/Xatom.h>
- #include <X11/Xlib.h>
- #include <X11/Xutil.h>
- ! typedef XPoint point_t;
- struct rect {
- int r_left, r_top, r_width, r_height;
- };
- #else /* X11 */
- + typedef struct pr_pos point_t;
- #include <suntool/tool_hs.h>
- #include <pixrect/pixrect_hs.h>
- #include <suntool/wmgr.h>
- ***************
- *** 88,93 ****
- --- 89,95 ----
- #define WidthOfScreen(s) s->pr_size.x
- #define HeightOfScreen(s) s->pr_size.y
- #define WUF_WMGR1 0x10
- + #define XFlush(dpy) /* not used in Suntools */
- #endif /* X11 */
-
- #include <sys/wait.h>
- ***************
- *** 118,124 ****
- /*
- * each {x,y} is a relative point to 0,0. End is {0,0} pair
- */
- ! struct pr_pos leaf[] = {
- {-4,4}, {-9,6}, {-13,9}, {-15,11}, {-16,14}, {-17,16}, {-17,20},
- {-16,24}, {-13,28}, {-11,30}, {-9,32}, {-4,36}, {-1,38}, {4,39}, {6,37},
- {4,37}, {3,34}, {3,31}, {4,29}, {6,25}, {9,20}, {10,16}, {10,12},
- --- 120,126 ----
- /*
- * each {x,y} is a relative point to 0,0. End is {0,0} pair
- */
- ! point_t leaf[] = {
- {-4,4}, {-9,6}, {-13,9}, {-15,11}, {-16,14}, {-17,16}, {-17,20},
- {-16,24}, {-13,28}, {-11,30}, {-9,32}, {-4,36}, {-1,38}, {4,39}, {6,37},
- {4,37}, {3,34}, {3,31}, {4,29}, {6,25}, {9,20}, {10,16}, {10,12},
- ***************
- *** 125,139 ****
- {8,8}, {7,7}, {4,6}, {2,4}, {1,0}, {0,2}, {-1,4}, {-3,8},
- {-5,12}, {-6,16}, {-6,20}, {-5,24}, {-3,27}, {0,0}
- };
- ! int leafsize = sizeof (leaf) / sizeof (struct pr_pos);
-
- ! struct pr_pos stem[50] = {
- {0,7}, {1,8}, {2,7}, {1,12}, {0,11}, {-1,12}, {-3,15}, {-3,19}, {-2,22},
- {-1,24}, {1,26}, {3,28}, {4,30}, {5,32}, {5,36}, {7,40}, {8,42}, {9,43},
- {8,49}, {5,51}, {2,54}, {0,60}, {0,0}
- };
- ! int stemsize = sizeof (stem) / sizeof (struct pr_pos);
- ! struct pr_pos leaves[360][sizeof(leaf) / sizeof(struct pr_pos)];
- struct rect win_rects[32];
-
- int reverse; /* -r: reverse video */
- --- 127,141 ----
- {8,8}, {7,7}, {4,6}, {2,4}, {1,0}, {0,2}, {-1,4}, {-3,8},
- {-5,12}, {-6,16}, {-6,20}, {-5,24}, {-3,27}, {0,0}
- };
- ! int leafsize = sizeof (leaf) / sizeof (point_t);
-
- ! point_t stem[50] = {
- {0,7}, {1,8}, {2,7}, {1,12}, {0,11}, {-1,12}, {-3,15}, {-3,19}, {-2,22},
- {-1,24}, {1,26}, {3,28}, {4,30}, {5,32}, {5,36}, {7,40}, {8,42}, {9,43},
- {8,49}, {5,51}, {2,54}, {0,60}, {0,0}
- };
- ! int stemsize = sizeof (stem) / sizeof (point_t);
- ! point_t leaves[360][sizeof(leaf) / sizeof(point_t)];
- struct rect win_rects[32];
-
- int reverse; /* -r: reverse video */
- ***************
- *** 150,163 ****
- int do_edges; /* -e: just traverse the edges of the screen */
- int do_windows; /* -w: grow around each open window in suntools */
- int season; /* -f: fall season */
- - int do_fork; /* -F: allow forking -- off for X */
- int fade; /* -D: fade the color down the colormap */
-
- ! unsigned long colors[256];
- int max_color; /* maximum number of colors available */
- int win_no, my_win; /* number of windows running / which win we are */
- int total_forks; /* the total number of forks we've done so far */
-
- #ifdef X11
- unsigned long intensity; /* shade of color to paint */
- Display *dpy; /* display */
- --- 152,166 ----
- int do_edges; /* -e: just traverse the edges of the screen */
- int do_windows; /* -w: grow around each open window in suntools */
- int season; /* -f: fall season */
- int fade; /* -D: fade the color down the colormap */
-
- ! unsigned long colors[255];
- int max_color; /* maximum number of colors available */
- int win_no, my_win; /* number of windows running / which win we are */
- int total_forks; /* the total number of forks we've done so far */
-
- + char *prog_name;
- +
- #ifdef X11
- unsigned long intensity; /* shade of color to paint */
- Display *dpy; /* display */
- ***************
- *** 185,190 ****
- --- 188,195 ----
- int c;
- int dead_kids();
-
- + prog_name = argv[0];
- +
- if (argc > 1)
- parse_args(argc, argv);
- else
- ***************
- *** 227,265 ****
- }
- }
-
- - #ifdef X11
- - {
- - void x_error();
- - char *getenv(), *p = getenv("DISPLAY");
- - if (!(dpy = XOpenDisplay(device? device : p? p : ""))) {
- - fprintf(stderr, "%s: unable to open display '%s'\n",
- - argv[0], XDisplayName(p));
- - exit(1);
- - }
- - /* XSynchronize(dpy, 1); */
- - XSetErrorHandler(x_error);
- - screen = ScreenOfDisplay(dpy, DefaultScreen(dpy));
- - win = RootWindowOfScreen(screen);
- - gc = XCreateGC(dpy, win, 0L, NULL);
- - }
- - #else /* X11 */
- - {
- - char groups[PIXPG_OVERLAY+1];
- - if (!(screen = pr_open(device)))
- - exit(1); /* pr_open prints its own error messages (bad idea) */
- -
- - pr_available_plane_groups(screen, sizeof(groups), groups);
- -
- - if (groups[PIXPG_OVERLAY] && groups[PIXPG_OVERLAY_ENABLE] && !is_color) {
- - pr_set_plane_group(screen, PIXPG_OVERLAY_ENABLE);
- - pr_rop(screen, 0,0, WidthOfScreen(screen), HeightOfScreen(screen),
- - PIX_SET, (Pixrect *) 0,0,0);
- - pr_set_plane_group(screen, PIXPG_OVERLAY);
- - }
- - do_fork++;
- - }
- - #endif /* X11 */
- -
- if (do_halt || from_center)
- /* don't count this fork ... */
- if (fork())
- --- 232,237 ----
- ***************
- *** 274,282 ****
- putchar('.');
- }
- puts(" done.");
- ! if (is_color)
- ! initialize_color();
- ! else if (do_windows) {
- if (!get_windows())
- puts("No windows!");
-
- --- 246,254 ----
- putchar('.');
- }
- puts(" done.");
- ! init_display();
- ! #ifndef X11
- ! if (!is_color && do_windows) {
- if (!get_windows())
- puts("No windows!");
-
- ***************
- *** 291,306 ****
- win_rects[my_win].r_top, FLOP);
- exit(0);
- }
- y = 1;
- if (do_edges) {
- ! if (do_fork) {
- ! if (!fork()) {
- ! edge_vines(WidthOfScreen(screen) / 2, 10, FLIP);
- ! exit(0);
- ! }
- ! } else
- edge_vines(WidthOfScreen(screen) / 2, 10, FLIP);
- ! edge_vines(WidthOfScreen(screen) / 2, 10, FLOP);
- exit(0);
- }
- #ifdef SIGCHLD
- --- 263,276 ----
- win_rects[my_win].r_top, FLOP);
- exit(0);
- }
- + #endif /* X11 */
- y = 1;
- if (do_edges) {
- ! if (!fork()) {
- ! init_display();
- edge_vines(WidthOfScreen(screen) / 2, 10, FLIP);
- ! } else
- ! edge_vines(WidthOfScreen(screen) / 2, 10, FLOP);
- exit(0);
- }
- #ifdef SIGCHLD
- ***************
- *** 312,320 ****
- random_vines(WidthOfScreen(screen)/2, HeightOfScreen(screen)/2);
- else
- random_vines(x, y);
- - #ifdef X11
- - XFlush(dpy);
- - #endif /* X11 */
- }
-
- #ifdef SIGCHLD
- --- 282,287 ----
- ***************
- *** 357,362 ****
- --- 324,330 ----
- draw_stem(&x, &y,
- (random() % 2) * UP | ((which_way == FLIP) ? FLOP : FLIP));
- */
- + XFlush(dpy);
- }
-
- random_vines(xstart, ystart)
- ***************
- *** 366,371 ****
- --- 334,340 ----
- total_forks++;
- return;
- }
- + init_display();
- /* make the child think there are too many forks */
- total_forks = MAX_FORKS;
- srandom((int) (getpid() * time((long *) 0)));
- ***************
- *** 375,380 ****
- --- 344,350 ----
- if (!(random() % (1 + (40 - branch_freq))))
- random_vines(xstart, ystart);
- }
- + XFlush(dpy);
- exit(0);
- }
-
- ***************
- *** 422,428 ****
-
- do_leaf(x,y)
- {
- ! int reverse_it;
- if (interleaf && (reverse_it = !(random() % interleaf)))
- reverse = !reverse;
- /* start at x,y and rotate */
- --- 392,398 ----
-
- do_leaf(x,y)
- {
- ! int reverse_it = 0;
- if (interleaf && (reverse_it = !(random() % interleaf)))
- reverse = !reverse;
- /* start at x,y and rotate */
- ***************
- *** 439,446 ****
- long mirror;
- {
- static col;
- ! int tmp, ox = x, oy = y, nx, ny, npts[1];
- ! struct pr_pos leaf2[sizeof(leaf) / sizeof(struct pr_pos)];
-
- /* magnify, move leaf into position, and mirror, if necessary */
- for(tmp = 0; tmp < leafsize; tmp++) {
- --- 409,419 ----
- long mirror;
- {
- static col;
- ! int tmp, ox = x, oy = y, nx, ny;
- ! #ifndef X11
- ! int npts[1];
- ! #endif
- ! point_t leaf2[sizeof(leaf) / sizeof(point_t)];
-
- /* magnify, move leaf into position, and mirror, if necessary */
- for(tmp = 0; tmp < leafsize; tmp++) {
- ***************
- *** 463,469 ****
- reverse = !reverse;
- #ifdef X11
- XFillPolygon(dpy, win, gc, leaf2, 28, Nonconvex, CoordModeOrigin);
- - XFlush(dpy);
- #else /* X11 */
- npts[0] = 28; /* kludge for middle line of leaf! */
- pr_polygon_2(screen, 0, 0, 1, npts, leaf2, RAS_OP, (Pixrect *) 0,0,0);
- --- 436,441 ----
- ***************
- *** 500,506 ****
-
- /* foreach pt in object, rotate_pt() */
- rotate_obj(object, newobject, npts, rotation)
- ! struct pr_pos object[], newobject[];
- double rotation;
- {
- int i;
- --- 472,478 ----
-
- /* foreach pt in object, rotate_pt() */
- rotate_obj(object, newobject, npts, rotation)
- ! point_t object[], newobject[];
- double rotation;
- {
- int i;
- ***************
- *** 510,516 ****
-
- /* matrix multiplication */
- rotate_pt(oldpt,newpt,rot)
- ! struct pr_pos *oldpt, *newpt;
- double rot;
- {
- /* temp storage -- might want to copy to itself */
- --- 482,488 ----
-
- /* matrix multiplication */
- rotate_pt(oldpt,newpt,rot)
- ! point_t *oldpt, *newpt;
- double rot;
- {
- /* temp storage -- might want to copy to itself */
- ***************
- *** 592,605 ****
- leaf_file = optarg;
- when 'S':
- stem_file = optarg;
- - when 'F':
- - do_fork = 1;
- when '?':
- errors = 1;
- }
-
- if (errors) {
- ! fprintf(stderr, err_msg[0], argv[0]);
- for (c = 1; err_msg[c]; c++)
- fprintf(stderr, "%s\n", err_msg[c]);
- exit(1);
- --- 564,575 ----
- leaf_file = optarg;
- when 'S':
- stem_file = optarg;
- when '?':
- errors = 1;
- }
-
- if (errors) {
- ! fprintf(stderr, err_msg[0], prog_name);
- for (c = 1; err_msg[c]; c++)
- fprintf(stderr, "%s\n", err_msg[c]);
- exit(1);
- ***************
- *** 608,619 ****
-
- #ifdef X11
- get_windows(){}
- initialize_color()
- {
- - u_char red[256], green[256], blue[256];
- - XColor color;
- Colormap cm = DefaultColormapOfScreen(screen);
-
- color.flags = DoRed | DoGreen | DoBlue;
- for (max_color = 0; max_color < 256; max_color++) {
- if (season) {
- --- 578,617 ----
-
- #ifdef X11
- get_windows(){}
- +
- + /*
- + * Open the display (connection to the X server). If it's already
- + * open, close it and reopen it since this is a child process and
- + * each child needs its own connection.
- + */
- + init_display()
- + {
- + int x_error(), first_time = !dpy;
- + char *getenv(), *p = getenv("DISPLAY");
- +
- + if (dpy)
- + XCloseDisplay(dpy);
- + if (!(dpy = XOpenDisplay(device? device : p? p : ""))) {
- + fprintf(stderr, "%s: unable to open display '%s'\n",
- + prog_name, XDisplayName(p));
- + exit(1);
- + }
- + XSetErrorHandler(x_error);
- + screen = ScreenOfDisplay(dpy, DefaultScreen(dpy));
- + win = RootWindowOfScreen(screen);
- + gc = XCreateGC(dpy, win, 0L, NULL);
- + if (first_time)
- + initialize_color();
- + XFlush(dpy);
- + }
- +
- + XColor color;
- initialize_color()
- {
- Colormap cm = DefaultColormapOfScreen(screen);
-
- + if (!is_color)
- + return;
- color.flags = DoRed | DoGreen | DoBlue;
- for (max_color = 0; max_color < 256; max_color++) {
- if (season) {
- ***************
- *** 624,638 ****
- color.green = (255 - max_color/3)<<8;
- }
- color.blue = (max_color/5)<<8;
- if (!XAllocColor(dpy, cm, &color)) {
- printf("ran out of colors at index %d\n", max_color--);
- break;
- }
- colors[max_color] = color.pixel;
- }
- }
-
- ! void
- x_error(display, error)
- Display *display;
- XErrorEvent *error;
- --- 622,640 ----
- color.green = (255 - max_color/3)<<8;
- }
- color.blue = (max_color/5)<<8;
- + if (dbug)
- + printf("%d=", max_color);
- if (!XAllocColor(dpy, cm, &color)) {
- printf("ran out of colors at index %d\n", max_color--);
- break;
- }
- colors[max_color] = color.pixel;
- + if (dbug)
- + printf("%d, ", color.pixel);
- }
- }
-
- ! int
- x_error(display, error)
- Display *display;
- XErrorEvent *error;
- ***************
- *** 651,661 ****
- XGetErrorDatabaseText(display, "XRequest", num, num, buffer, BUFSIZ);
- fprintf(stderr, " %s\n", buffer);
-
- /* abort to core dump or global debug flag set.. */
- ! abort(0);
- }
-
- #else /* X11 */
- get_windows()
- {
- char name[WIN_NAMESIZE];
- --- 653,685 ----
- XGetErrorDatabaseText(display, "XRequest", num, num, buffer, BUFSIZ);
- fprintf(stderr, " %s\n", buffer);
-
- + printf("color.red = %d, green = %d, blue = %d, pixel = %d\n",
- + color.red>>8, color.green>>8, color.blue>>8, color.pixel);
- /* abort to core dump or global debug flag set.. */
- ! /* abort(0); */
- ! exit(0);
- }
-
- #else /* X11 */
- +
- + init_display()
- + {
- + char groups[PIXPG_OVERLAY+1];
- + if (screen)
- + return;
- + if (!(screen = pr_open(device)))
- + exit(1); /* pr_open prints its own error messages (bad idea) */
- +
- + pr_available_plane_groups(screen, sizeof(groups), groups);
- +
- + if (groups[PIXPG_OVERLAY] && groups[PIXPG_OVERLAY_ENABLE] && !is_color) {
- + pr_set_plane_group(screen, PIXPG_OVERLAY_ENABLE);
- + pr_rop(screen, 0,0, WidthOfScreen(screen), HeightOfScreen(screen),
- + PIX_SET, (Pixrect *) 0,0,0);
- + pr_set_plane_group(screen, PIXPG_OVERLAY);
- + }
- + }
- +
- get_windows()
- {
- char name[WIN_NAMESIZE];
- dan
- -----------------------------------------------------------
- O'Reilly && Associates
- argv@sun.com / argv@ora.com
- 632 Petaluma Ave, Sebastopol, CA 95472
- 800-338-NUTS, in CA: 800-533-NUTS, FAX 707-829-0104
- Opinions expressed reflect those of the author only.
-